<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<%
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String gd_content_id = request.getParameter("gd_content_id") == null ? "" : request.getParameter("gd_content_id");
	String dept_id = request.getParameter("dept_id") == null ? "" : request.getParameter("dept_id");
	String dept_name = request.getParameter("dept_name") == null ? "" : request.getParameter("dept_name");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
	String customer_id = request.getParameter("customer_id") == null ? "" : request.getParameter("customer_id");
	String customer = request.getParameter("customer") == null ? "" : request.getParameter("customer");
	String borrow_id = request.getParameter("borrow_id") == null ? "" : request.getParameter("borrow_id");
%>
<html>
	<head>
		<title>客户库借料明细</title>
	<script type="text/javascript">
		$(function(){
			$('#table').datagrid({
				url:'<%=contextPath%>/springMVC/gd/listGDCustomerBorrowDetail?gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>&borrow_id=<%=borrow_id%>',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				columns:[[
					{title:'产品编号',field:'code',width:100,align:'center'},
					{title:'产品名称',field:'name',width:100,align:'center'},
					{title:'规格/型号',field:'format_type',width:100,align:'center'},
					{title:'单位',field:'unit_name',width:50,align:'center'},
					{title:'预算数量',field:'assume_num',width:100,align:'center'},
					{field:'control',hidden:true},
					{title:'管控最大值',field:'max_num',width:100,align:'center',formatter:function(value,row,index){
				    	   var assume_num = parseFloat(row.assume_num);
				    	   var control = parseFloat(row.control)/100;
				    	   row.max_num = Math.round(assume_num*(1+control)*Math.pow(10,2))/Math.pow(10,2);
				    	   return row.max_num;
				     }},
					{title:'已使用数',field:'already_use',width:100,align:'center'},
					{title:'审批占用数',field:'queue_num',width:100,align:'center'},
					{title:'申请数量',field:'num',width:100,align:'center'},
					{title:'备注',field:'remark',width:100,align:'center'}
				]],
				rowStyler : function(index,row){
				    var assume_num = parseFloat(row.assume_num);
		    	    var control = parseFloat(row.control)/100;
		    	    var max_num = Math.round(assume_num*(1+control)*Math.pow(10,2))/Math.pow(10,2);
					if(parseFloat(max_num) < parseFloat(row.already_use)+parseFloat(row.queue_num)+parseFloat(row.num))
					{	
						return 'background-color:#ffee00;color:red;';
					}
				},
				toolbar:'#tb'
			});
		});
		function sumbitObj(obj){
			var jsondata=$("#table").datagrid("getData");
			for(var i=0;i<jsondata.total;i++){
				var index = $("#table").datagrid("getRowIndex",jsondata.rows[i])+1;
				if(parseFloat(jsondata.rows[i].num)+parseFloat(jsondata.rows[i].queue_num)+parseFloat(jsondata.rows[i].already_use) > parseFloat(jsondata.rows[i].max_num)){
					$.messager.alert('提示','第'+index+'行数量已经超出管控最大范围！');
					return ;
				}
			}
			
		      $(obj).hide();
		      var id = '<%=borrow_id%>';
		      var flowBusinessUrl='<%=contextPath %>/springViews/gd/addOrEditCustomerBorrow.jsp?isShow=1&gd_id=<%=gd_id%>&gd_content_id=<%=gd_content_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&customer_id=<%=customer_id%>&customer=<%=customer%>&borrow_id='+id;
		      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_BORROW_CUSTOMER_SHENPI%>")+"&businessId="+id;
		      $(obj).hide();
		      $.ajax({
							type:'POST',
							url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
							dataType:"JSON",
							data:param,
							success:function(rtJson){
								if (rtJson.rtState == '0'){
									openDialogResize(rtJson.rtData.url,1000,800);
									window.close();
								}else{
									warningInfo(rtJson.rtMsrg);
								}
								$(obj).show();
							}
						});
		}
	</script>
	</head>
	<body>
		<div id="table"></div>
						<div id="tb" style="padding:3px;height:auto">
						<div align="left">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="sumbitObj(this);">提交审批</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
						</div>
					</div>
		
	</body>
</html>